<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class UserProfile.
 * @property int $id
 * @property int $user_id
 * @property string $name
 * @property string $phone
 * @property string $address
 * @property string $native_place
 * @property string $id_card_number
 * @property string $flow_register_code
 * @property string $pass_card_photo
 * @property string birthday
 * @property string created_at
 * @property int check_status
 * @property int identity
 * @property int is_company
 * @property int area
 * @property int houser_score
 * @property int need_check_house_number
 * @property int check_adopt_house_number
 * @property int successive_not_in_village_days
 */
class UserProfile extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $guarded = [];

    protected $casts = [
        'created_at' => 'date:Y-m-d H:i:s',
        'updated_at' => 'date:Y-m-d H:i:s',
    ];

    public function userAssessLog()
    {
        return $this->hasMany(UserAssessLog::class);
    }

    public function houses()
    {
        return $this->hasMany(House::class, 'houser_user_id', 'user_id');
    }

    public function house()
    {
        return $this->hasMany(House::class, 'houser_user_id', 'user_id');
    }

    public function score_result()
    {
        return $this->hasOne(HouserScoreResult::class, 'houser_id', 'user_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function industryEnum()
    {
        return $this->belongsTo(Enum::class, 'industry', 'id');
    }

    public function assessLog()
    {
        return $this->hasMany(UserAssessLog::class);
    }

    public function check()
    {
        return $this->hasOne(CheckUserProfile::class, 'id_card_number', 'id_card_number');
    }

    public function houseBind()
    {
        return $this->hasOne(HouseUserBind::class, 'id_card_number', 'id_card_number');
    }

    public function getVaccinationScreenshotPathAttribute($value)
    {
        if (empty($value)) {
            return $value;
        }
        if (substr($value, 0, 4) != 'http') {
            return config('app.url') . $value;
        }
        return $value;
    }
}
